import {Component, OnInit} from '@angular/core';
import {Observable} from 'rxjs';
import {FormControl} from '@angular/forms';
import {debounceTime, filter} from 'rxjs/operators';

@Component({
  selector: 'app-response',
  templateUrl: './response.component.html',
  styleUrls: ['./response.component.css']
})
export class ResponseComponent implements OnInit {

  /*每一次值改变就会有对应的请求发送*/
  searchInput: FormControl = new FormControl();

  birthday: Date = new Date();

  pi: number = 3.141592657;
  /*
    创建	from, fromPromise,fromEvent, of
    组合	combineLatest, concat, merge, startWith , withLatestFrom, zip
    过滤	debounceTime, distinctUntilChanged, filter, take, takeUntil
    转换	bufferTime, concatMap, map, mergeMap, scan, switchMap
    工具	tap
    多播	share
  */
  constructor() {
    this.searchInput
      .valueChanges.pipe(
      /*设置事件请求时间*/
      debounceTime(500),
      /*过滤设置*/
      filter(e => e % 2 == 0)
    )
      .subscribe(stockCode => this.getStockInfo(stockCode));
  }

  ngOnInit() {
  }

  getStockInfo(value: string) {
    console.log(value);
  }
}
